package team.seekers.hula.teamwork.team.team.controller;


import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.result.ApiExceptionEnum;
import team.seekers.hula.common.entity.result.ApiException;
import team.seekers.hula.teamwork.team.team.entity.dto.TeamAddPA;
import team.seekers.hula.teamwork.team.team.entity.dto.TeamUpdatePA;
import team.seekers.hula.teamwork.team.team.entity.vo.TeamInfoVO;
import team.seekers.hula.teamwork.team.team.entity.vo.TeamListVO;
import team.seekers.hula.teamwork.team.team.service.TeamService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 团队 前端控制器
 * @author yiming
 */

@Controller
@ApiResponseBody
@RequestMapping("/team")
public class TeamController {

    @Resource
    private TeamService teamService;


    @ApiOperation(value = "根据团队id获取团队详细信息")
    @GetMapping("/get")
    public TeamInfoVO getById(@RequestParam String id) {
        return teamService.get(id);
    }


    @ApiOperation(value = "渲染所有创建的团队")
    @GetMapping("/list-me-create")
    public List<TeamListVO> listMeCreate() {
        return teamService.listMeCreate();
    }


    @ApiOperation(value = "渲染所有加入的团队")
    @GetMapping("/list-me-in")
    public List<TeamListVO> listMeIn() {
        return teamService.listMeIn();
    }


    @ApiOperation(value = "新建团队")
    @PostMapping("/add")
    public void add(@RequestBody TeamAddPA teamAddPA) {
        teamService.add(teamAddPA);
    }


    @ApiOperation(value = "编辑团队")
    @PostMapping("/update")
    public void update(@RequestBody TeamUpdatePA teamUpdatePA) {
        teamService.update(teamUpdatePA);
    }


    @ApiOperation(value = "解散团队")
    @DeleteMapping("/delete")
    public void delete(@RequestParam String id) {
        teamService.delete(id);
    }


    @ApiOperation(value = "加入团队")
    @GetMapping("/in")
    public void joinIn(@RequestParam String id) {
        teamService.joinIn(id);
    }

    @ApiOperation(value = "加入班级")
    @GetMapping("/class-bind")
    public void bindClass(@RequestParam String inviteCode) {
        if(teamService.isExist(inviteCode)){
            teamService.bindClass(inviteCode);
        }else {
            throw new ApiException(ApiExceptionEnum.TEAM_NOT_FOUND);
        }
    }

    @ApiOperation(value = "退出团队")
    @GetMapping("/out")
    public void out(@RequestParam String id) {
        teamService.out(id);
    }


}

